package com.allwees.bs.c.module.order.chain.create.request;

import com.allwees.core.common.constant.EPlatform;
import lombok.Data;
import lombok.experimental.Accessors;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

@Data
@Accessors(chain = true)
public class OrderCreateRequest {
    /** 送货地址 */
    private String shippingAddressUuid;

    /** 支付类型 */
    private Integer paymentType;

    /** 用户优惠券uuid **/
    private String userCouponUuid;

    private String userCouponNo;

    /** user promo log uuid **/
    private String userPromoLogUuid;

    /** 推广码 **/
    private String promoCode;

    /** 是否购买运费险 **/
    private boolean buyShippingInsurance;

    /** 用户uuid */
    private String userUuid;

    /** 邀请用户uuid */
    private String inviterUserUuid;

    /** 订单类型 */
    private Integer orderType;

    /** 平台 **/
    private EPlatform platform;

    //================================================

    /** uuid */
    private String uuid;

    /** no */
    private String no;

    //===============================
    /** 商品数量 */
    private Integer sum;

    /** 总金额 */
    private BigDecimal amt = BigDecimal.ZERO;

    /** 商品总价 */
    private BigDecimal amtProduct  = BigDecimal.ZERO;

    /** 加价后商品总价 */
    private BigDecimal amtProductAfterAdd  = BigDecimal.ZERO;

    /** 运费 */
    private BigDecimal amtShipping  = BigDecimal.ZERO;

    /** 加价后运费总价 */
    private BigDecimal amtShippingAfterAdd  = BigDecimal.ZERO;

    /** 优惠总额 */
    private BigDecimal amtDiscount = BigDecimal.ZERO;

    /** 运费优惠金额 */
    private BigDecimal amtShippingDiscount = BigDecimal.ZERO;

    /** 商品优惠金额  */
    private BigDecimal amtProductDiscount = BigDecimal.ZERO;

    /**
     * 商品优惠金额
     **/
    private BigDecimal amtProductCoupon;

    /** 用户现金抵扣金额 */
    private BigDecimal amtCash = BigDecimal.ZERO;

    /** 原始运费金额 */
    private BigDecimal originalAmtShipping  = BigDecimal.ZERO;

    /** 原始商品金额 */
    private BigDecimal originalAmtProduct  = BigDecimal.ZERO;

    /** 原始实际金额 */
    private BigDecimal originalAmt  = BigDecimal.ZERO;

    /** 商家订单金额 */
    private BigDecimal merchantAmt = BigDecimal.ZERO;

    /** 平台订单金额 */
    private BigDecimal platformAmt =  BigDecimal.ZERO;

    /** 营业税 */
    private BigDecimal originalAmtSaleTax  = BigDecimal.ZERO;

    /** 营业税 */
    private BigDecimal amtSaleTax  = BigDecimal.ZERO;

    /**加价后的营业税 */
    private BigDecimal amtSaleTaxAfterAdd  = BigDecimal.ZERO;

    private BigDecimal discountRate = BigDecimal.ZERO;

    private List<OrderItemCreateRequest> items;

    private boolean isCheckOrder = false;

    /**
     * 渠道 uuid
     */
    private String orderChannelUuid;

    public Set<String> itemSkuUuids(){
        return items.stream().map(OrderItemCreateRequest::getSkuUuid).collect(Collectors.toSet());
    }

    public Map<String, OrderItemCreateRequest> itemMapBySkuUuid(){
        return items.stream().collect(Collectors.toMap(OrderItemCreateRequest::getSkuUuid, o -> o));
    }

    public Map<String, OrderItemCreateRequest> itemMapByUuid() {
        return items.stream().collect(Collectors.toMap(OrderItemCreateRequest::getUuid, o -> o));
    }

    public boolean isAmtPayedOfCoupon() {
        return BigDecimal.ZERO.compareTo(amt) == 0;
    }
}
